#pragma once

#include <QThread>
#include <QMutex>
#include <QWaitCondition>


namespace rviz_custom_plugins
{

namespace av_codec {

class VideoDecoder : public QThread {
    Q_OBJECT
public:
    explicit VideoDecoder(QObject *parent = nullptr);
    ~VideoDecoder();

    bool startPlay(const QString &url);
    void stop();
    void pause();
    void resume();

signals:
    void frameReady(const QImage &frame);
    void error(const QString &msg);

protected:
    void run() override;

private:
    void cleanup();

    QString m_url;
    std::atomic<bool> m_running{false};
    std::atomic<bool> m_paused{false};
    QMutex m_mutex;
    QWaitCondition m_pauseCond;
};

}

}
